package org.lyq.erp.config.fileupload.ftp;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 配置ftp服务器的相关参数
 * 
 * @author LYQ
 *
 */
public class FtpConfig {

	private static Logger logger = LoggerFactory.getLogger(FtpConfig.class);

	// Ftp的ip地址
	private String ftpAddress;

	// Ftp服务器的端口号
	private String ftpPort;

	// Ftp服务器的登陆名
	private String ftpUsername;

	// Ftp服务器的登陆名的密码
	private String ftpPassword;

	// Ftp服务器的文件上传的基本路径
	private String ftpBasepath;

	// 图片下载的基础路径
	private String fileBaseUrl;

	private static FtpConfig instance;

	private FtpConfig() {

	}

	public static synchronized FtpConfig getInstance() {

		if (instance == null) {
			instance = new FtpConfig();
			instance.setFtpConfigFiled();
		}

		return instance;
	}

	private void setFtpConfigFiled() {

		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("application.properties");
		if (inputStream != null) {
			Properties properties = new Properties();
			try {
				properties.load(inputStream);

				this.ftpAddress = properties.getProperty("FTP_ADDRESS");
				this.ftpPort = properties.getProperty("FTP_PORT");
				this.ftpPassword = properties.getProperty("FTP_PASSWORD");
				this.ftpUsername = properties.getProperty("FTP_USERNAME");
				this.fileBaseUrl = properties.getProperty("IMAGE_BASE_URL");
				this.ftpBasepath = properties.getProperty("FTP_BASEPATH");
			} catch (IOException e) {
				logger.error(e.getMessage());
				logger.info("get Ftp config is failed");
			}
		}
		logger.info("ftp inputStream is null");
	}

	public static Logger getLogger() {
		return logger;
	}

	public String getFtpAddress() {
		return ftpAddress;
	}

	public String getFtpPort() {
		return ftpPort;
	}

	public String getFtpUsername() {
		return ftpUsername;
	}

	public String getFtpPassword() {
		return ftpPassword;
	}

	public String getFtpBasepath() {
		return ftpBasepath;
	}

	public String getFileBaseUrl() {
		return fileBaseUrl;
	}

}
